<?php
/* Class BadgeAssertion 
 * Documentation can be found at:
 * https://github.com/mozilla/openbadges/wiki/Assertions#badgeassertion */

class BadgeAssertion {
	
	/* Mandatory fields */
	private $uid;
	private $recipient;
	private $badge;
	private $verify;
	private $issuedOn;
	
	/* Optional fields */
	private $image;
	private $evidence;
	private $expires;
	
	/* Getters & Setters */
	public function getUID() {
		return $this->uid;
	}
	
	public function setUID($uid) {
		$this->uid = $uid;
	}
	
	public function getRecipient() {
		return $this->recipient;
	}

	public function setRecipient($recipient) {
		$this->recipient = $recipient;
	}
	
	public function getBadge() {
		return $this->badge;
	}

	public function setBadge($badge) {
		$this->badge = $badge;
	}
	
	public function getVerify() {
		return $this->verify;
	}

	public function setVerify($verify) {
		$this->verify = $verify;
	}
	
	public function getIssuedOn() {
		return $this->issuedOn;
	}

	public function setIssuedOn() {
		$this->issuedOn = time();
	}
	
	public function getImage() {
		return $this->image;
	}
	
	public function setImage($image) {
		$this->image = $image;
	}
	
	public function getEvidence() {
		return $this->evidence;
	}
	
	public function setEvidence($evidence) {
		$this->evidence = $evidence;
	}
	
	public function getExpires() {
		return $this->expires;
	}
	
	public function setExpires($expires) {
		$this->expires = $expires;
	}
	
	public function checkValidity() {
		return isset($this->uid) && isset($this->recipient) && isset($this->badge) && 
			isset($this->verify) && isset($this->issuedOn);
	}
	
	public function getArray() {
		
		if (!$this->checkValidity())
			return null;
		
		$array["uid"] = $this->uid;
		$array["recipient"] = $this->recipient;
		$array["badge"] = $this->badge;
		$array["verify"] = $this->verify;
		$array["issuedOn"] = $this->issuedOn;
		
		if (isset($this->image))
			$array["image"] = $this->image;
		
		if (isset($this->evidence))
			$array["evidence"] = $this->evidence;
		
		if (isset($this->expires))
			$array["expires"] = $this->expires;
		
		return $array;
	}
}
?>
